enum EnumDataType {
    number = "[object Number]",
    string = "[object String]",
    boolean = "[object Boolean]",
    null = "[object Null]",
    undefined = "[object Undefined]",
    object = "[object Object]",
    array = "[object Array]",
    date = "[object Date]",
    regexp = "[object RegExp]",
    set = "[object Set]",
    map = "[object Map]",
    function = "[object Function]",
    promise = "[object Promise]"
}

function is(val: unknown, type: EnumDataType) {
    return Object.prototype.toString.call(val) === type
}

export function isNumber(data: unknown) {
    return is(data, EnumDataType.number)
}

export function isString(data: unknown) {
    return is(data, EnumDataType.string)
}

export function isBoolean(data: unknown) {
    return is(data, EnumDataType.boolean)
}

export function isNull(data: unknown) {
    return is(data, EnumDataType.null)
}

export function isUndefined(data: unknown) {
    return is(data, EnumDataType.undefined)
}

export function isObject(data: unknown) {
    return is(data, EnumDataType.object)
}

export function isArray(data: unknown) {
    return is(data, EnumDataType.array)
}

export function isDate(data: unknown) {
    return is(data, EnumDataType.date)
}

export function isRegExp(data: unknown) {
    return is(data, EnumDataType.regexp)
}

export function isSet(data: unknown) {
    return is(data, EnumDataType.set)
}

export function isMap(data: unknown) {
    return is(data, EnumDataType.map)
}

export function isFunction(data: unknown) {
    return is(data, EnumDataType.function)
}

export function isPromise(data: any) {
    return is(data, EnumDataType.promise) && isFunction(data.then) && isFunction(data.catch)
}

export function isNullOrUnDef(data: unknown) {
    return isNull(data) || isUndefined(data)
}

/**
 * 可以判断 Array、String、Map、Set、Object 类型是否为空
 * @param data 数据
 * @returns boolean
 */
export function isEmpty(data: any) {
    if (isNullOrUnDef(data)) {
        return true
    }
    if (isArray(data) || isString(data)) {
        return data.length === 0
    }
    if (isMap(data) || isSet(data)) {
        return data.size === 0
    }
    if (isObject(data)) {
        return Object.keys(data).length === 0
    }
    return false
}
